#!/bin/bash
set +e

echo "start php-fpm"
php-fpm7.0 -c /code/.fun/root/usr/lib/php/7.0/php.ini-production -y /code/.fun/root/etc/php/7.0/fpm/php-fpm.conf 

echo "start nginx"
nginx -c /code/.fun/root/etc/nginx/nginx.conf 

sleep 5

while true
do
    echo "check ...."
    nginx_server=`ps aux | grep nginx | grep -v grep`
    if [ ! "$nginx_server" ]; then
        echo "restart nginx ..."
        nginx -c /code/.fun/root/etc/nginx/nginx.conf 
    fi
    php_fpm_server=`ps aux | grep php-fpm | grep -v grep`
    if [ ! "$php_fpm_server" ]; then
        echo "restart php-fpm ..."
        php-fpm7.0 -c /code/.fun/root/usr/lib/php/7.0/php.ini-production -y /code/.fun/root/etc/php/7.0/fpm/php-fpm.conf 
    fi
    sleep 10
done